package com.sharefang.aproject.presenter;

import android.os.Handler;

import com.sharefang.aproject.bean.NppBean;
import com.sharefang.aproject.biz.npp.INppBiz;
import com.sharefang.aproject.biz.npp.NppBiz;
import com.sharefang.aproject.biz.npp.OnNppResultListener;
import com.sharefang.aproject.view.INppView;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/8/16.
 */

public class GetNppPresenter {
    private INppBiz nppBiz;
    private INppView nppView;
    private Handler mHandler = new Handler();
    private String url;

    public GetNppPresenter(String url, INppView nppView) {
        this.url = url;
        this.nppView = nppView;
        this.nppBiz = new NppBiz();
    }

    public void getNpp( Map<String, Object> map, final boolean loadMore) {
        nppBiz.getNpp(url, map, loadMore, new OnNppResultListener() {
            @Override
            public void onSuccess(final List<NppBean> nppBeens) {
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        nppView.doGetNpp(nppBeens, loadMore);
                    }
                });
            }

            @Override
            public void onFailure(final String message) {
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        nppView.showFailedError(message);
                    }
                });
            }
        });
    }
}
